//search and replace Rain with whatever your classname is


import javax.swing.*;
import java.awt.*;
import java.util.Random;

public class Rain implements Runnable
{
	int[] x, xy, xspeed, yspeed;
	int[] y, yx;
	int n, width, height;
	int acceleration = 1;
	final int SPAWN_NUM, SPEED1, RAIN_WIDTH, RAIN_LENGTH;
	boolean gonethrough, poop;
	JPanel window;
	public Rain(int w, int h, JPanel jp)
	{
		width = w;
		height = h;
		n = 0;
		SPAWN_NUM = 200;
		x = new int[SPAWN_NUM];
		y = new int[SPAWN_NUM];
		xy = new int[SPAWN_NUM];
		yx = new int[SPAWN_NUM];
		xspeed = new int[SPAWN_NUM];
		yspeed = new int[SPAWN_NUM];
		SPEED1 = 5;
		RAIN_WIDTH = 5;
		RAIN_LENGTH = 5;
		window = jp;



	}
	public void run()
	{
		while(true) {

			if (n == SPAWN_NUM)
			{
			n = 0;
			gonethrough = true;
			}
			int i = SPAWN_NUM;
			if (!gonethrough)
			{
				Random rng = new Random();
	
				x[n] = rng.nextInt(width) + 1;
				xspeed[n] = rng.nextInt(5) + 5;

				i = n;
			}
	

			for(int count = 0; count < i; count++)
			{
				//draw the current rectangle
				Graphics g = window.getGraphics();
				window.paintImmediately(x[count], xy[count], RAIN_WIDTH, RAIN_LENGTH);
				
				
				xy[count] += xspeed[count];
				x[count]+= xspeed[count];
				
				if (x[count] >= width)
					x[count] -= width;

				if (xy[count] > height-RAIN_LENGTH)
					xy[count] = 0;
				
				g.setColor(chooseColor());
				g.fillRect(x[count], xy[count], RAIN_WIDTH, RAIN_LENGTH);
			}
			


			n++;
			
			try {
				Thread.sleep(25);
			} catch (InterruptedException e) {
				
			}
		}
	}
	protected Color chooseColor()
		{
			Random rng = new Random();
			return new Color(rng.nextInt(256), rng.nextInt(256), rng.nextInt(256));


	}
}